def __get_fc__(category):

    if request.args(0) and request.args(1):
                
        res = db(db.fc.category == category).select(orderby=~db.fc.count,
                                                      limitby=(int(request.args[0]), int(request.args[1])))
    else:
        
        if request.args(0):
        
            res = db((db.fc.category == category) & (db.fc.count == request.args[0])).select(orderby=~db.fc.count)
            
        else:
        
            res = db(db.fc.category == category).select(orderby=~db.fc.count)           
    
    groups = {}
    for r in res:
        groups.setdefault(r.count, [])
        groups[r.count].append(r.feature)
        
                                
    return groups


def favorite():

    res = __get_fc__('favorite')
    
    return dict(res)


def spam():

    res = __get_fc__('spam')
    
    return dict(res)
